import Cookies from 'js-cookie'

const language = 'VSE-Language';

/**
 * 用于设置APP基础配置的store
 *
 * mixWidth = 一级菜单的总宽度 + 顶部LOGO的宽度*2
 */
const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('sidebarStatus'),
      withoutAnimation: false
    },
    device: 'desktop',
    language: Cookies.get(language) || 'zh',
    mixHeight : 768,
    mixWidth : 1366,
    beforeRouteUpdateActive: false,
  },
  mutations: {
    SET_LANGUAGE: (state, language) => {
      state.language = language
      Cookies.set(language, language)
    },
    SET_BEFOREROUTEUPDATEACTIVE: (state, beforeRouteUpdateActive) => {
      state.beforeRouteUpdateActive = beforeRouteUpdateActive
    },
  },
  actions: {
    setLanguage({ commit }, language) {
      commit('SET_LANGUAGE', language)
    },
    setBeforeRouteUpdateActive({ commit }, beforeRouteUpdateActive) {
      commit('SET_BEFOREROUTEUPDATEACTIVE', beforeRouteUpdateActive)
    },
  }
};

export default app
